package dcutils.cards.mtg;

/**
 * Represents a single basic land card in Magic the Gathering.<br/>
 * @author dca
 */
public class BasicLandCard extends Card {
	/** The mana associated with this land.<br/> */
	private BaseMana mana;

	/**
	 * The constructor initializes the land as a common card type.<br/>
	 * @param mana The mana associated with this land.<br/>
	 * @param expansion The Magic the Gathering expansion associated with this land.<br/>
	 */
	public BasicLandCard(BaseMana mana, Expansion expansion) {
		super(mana.getLand(), Rarity.COMMON, expansion, String.format("Basic Land - %s", mana.getLand()));
		setMana(mana);
	} // END constructor

	/**
	 * Getter for the mana associated with this land.<br/>
	 * @return BaseMana The mana associated with this land.<br/>
	 */
	public BaseMana getMana() {
		return this.mana;
	} // END getMana

	/**
	 * Setter for the mana associated with this land.<br/>
	 * @param mana The mana associated with this land.<br/>
	 * @return this.<br/>
	 */
	public BasicLandCard setMana(BaseMana mana) {
		this.mana = mana;
		return this;
	} // END setMana

	/**
	 * Returns all the properties associated with this land card.<br/>
	 * @return String A string representing this land card.<br/>
	 */
	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer(1024);
		buffer.append(this.getClass().getSimpleName()); buffer.append(" [");

		buffer.append(String.format("%s = %s", "landName", getCardName()));
		buffer.append(", ");
		buffer.append(String.format("%s = %s", "rarity", getRarity()));
		buffer.append(", ");
		buffer.append(String.format("%s = %s", "expansion", getExpansion()));
		buffer.append(", ");
		buffer.append(String.format("%s = %s", "typeLine", getTypeLine()));

		buffer.append("]");
		return buffer.toString();
	} // END toString

	/**
	 * Decides if an object is equal to this land card.<br/>
	 * In order for an object to be equal to this land card:<br/>
	 * the object must also be the same type, must not be null, and each of its items must equal this land&apos;s items.<br/>
	 * @param obj The item to check for value equality.<br/>
	 * @return True or false<br/>
	 */
	@Override
	public boolean equals(Object obj) {
		if(null == obj) {
			return false;
		} else if(obj instanceof BasicLandCard) {
			BasicLandCard card = (BasicLandCard)obj;
			return this.toString().equals(card.toString()) &&
				   this.getMana().equals(card.getMana());
		} else {
			return false;
		} // END if/else
	} // END equals

	/**
	 * Creates a hash code for this land card.<br/>
     * The hash code uses prime numbers and the hash code of the super class.<br/>
     * @return integer The hash code.<br/>
	 */
	@Override
	public int hashCode() {
		int hashCode = 101;
		hashCode = (11 * hashCode) + super.hashCode();
		return hashCode;
	} // END hashCode

	/**
	 * Returns all the properties associated with this land card in a tab-indented, new-line delimited string.<br/>
	 * @return String A string representing this land card.<br/>
	 */
	@Override
	public String prettyPrint() {
		StringBuffer buffer = new StringBuffer(1024);
		buffer.append(this.getClass().getSimpleName()); buffer.append(String.format(" [%n"));

		buffer.append(String.format("\t%s = %s", "landName", getCardName()));
		buffer.append(String.format(",%n"));
		buffer.append(String.format("\t%s = %s", "rarity", getRarity()));
		buffer.append(String.format(",%n"));
		buffer.append(String.format("\t%s = %s", "expansion", getExpansion()));
		buffer.append(String.format(",%n"));
		buffer.append(String.format("\t%s = %s", "typeLine", getTypeLine()));

		buffer.append(String.format("%n]"));
		return buffer.toString();
	} // END prettyPrint
} // END class BasicLandCard
